/*此文件为主文件*/
import Vuex from 'vuex'
import defaultState from './state/state.js'
import getters from './getters/getters.js'
import mutations from './mutations/mutations.js'
import actions from './actions/actions.js'

const isDev = process.env.NODE_ENV === 'development';

export default () => {
	const store = new Vuex.Store({
        strict:isDev,  //在开发环境中开启vuex的严格模式
		state:defaultState, //定义需要用到的状态,
		getters, //获取state中的值,并且进行计算
		mutations, //让commit动作修改的值映射到state上
		actions	//对mutations中的多个commit函数进行封装
	})
	if(module.hot){//如果webpack启动了热加载
		module.hot.accept([
			'./state/state.js',
			'./getters/getters.js',
			'./mutations/mutations.js',
			'./actions/actions.js'
		],()=>{
			const newState = require('./state/state.js').default
			const newGetters = require('./getters/getters.js').default
			const newMutations = require('./mutations/mutations.js').default
			const newActions = require('./actions/actions.js').default

			store.hotUpdate({
				state:newState,
				getters:newGetters,
				mutations:newMutations,
				actions:newActions
			})
		})
	}
	return store;
}